/* This file is part of BonQ - A simple HTTP-based messaging server.
 * Copyright (C) 2009 James Cook
 *
 * BonQ is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License, version 2, as published by the
 * Free Software Foundation.
 *
 * BonQ is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License, version 2,
 * for more details.
 *
 * You should have received a copy of the GNU General Public License, version
 * 2, along with BonQ.  If not, see:
 *
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */
package com.bonkabonka.queue;

/**
 * This queue only ever contains one entry.  Pushing a new value into it
 * replaces the current value.  Pull chains to peek so the value is never
 * removed.  On shutdown its value is lost and on initialization its value
 * is set to "unknown".
 * 
 * @author jamesc
 */
public class StatusQueue extends Queue
{
    private transient String status;

    /**
     * Initialize the queue.  Set the initial value of the queue to "unknown".
     * 
     * @param bucket QueueBucket which is not used
     */
    @Override
    public void init(QueueBucket bucket, String name)
    {
        super.init(bucket, name);
        
        status = "unknown";
    }
    
    /**
     * Set the queue's value.
     * 
     * @param message String containing the message
     * @return null
     */
    public String push(String message)
    {
        this.status = message;

        return null;
    }

    /**
     * Returns the queue's value.
     * 
     * @return String containing the queue's value
     */
    public String peek()
    {
        return status;
    }

    /**
     * Same as peek.
     * 
     * @see #peek
     * 
     * @return String containing the queue's value
     */
    public String pull()
    {
        return peek();
    }
}
